/********************************************************************
	file base:	Utility
	file ext:	h
	author:		JiangHuai
	
	purpose:	Utility function
*********************************************************************/

#ifndef UTILITY
#define UTILITY

#include <string>
#include "Lib/CXImage600/include/ximage.h"
#include <winnt.h>
#include <stdlib.h>

using namespace std;

string getFileExt(string path) {
	int index = path.find_last_of(".");
	return path.substr(index+1, path.length()-1);
}

ENUM_CXIMAGE_FORMATS getFormat(const TCHAR filePathName[]) {
	string pathName((char*)filePathName);
	string extension = getFileExt(pathName);
	if (extension=="bmp") {
		return CXIMAGE_FORMAT_BMP;
	}
	if (extension=="jpg") {
		return CXIMAGE_FORMAT_JPG;
	}
	if (extension=="gif") {
		return CXIMAGE_FORMAT_GIF;
	}
	if (extension=="tif") {
		return CXIMAGE_FORMAT_TIF;
	}

	return CXIMAGE_FORMAT_UNKNOWN;
}

#endif